


var AllUrl = 'http://hsmy.vrdete.com/';//当前地址 2018-06-25更新
var IMGUrl  = 'http://p2816srbo.bkt.clouddn.com/';//图片地址
var modDot = ' <span class="layui-badge-dot"></span>'//红色的代表可以编辑的圆点
var UpStr = ['']

function AjaxPostFn(Url,jsondata,callBack  ,  needkey){
	// if(localStorage.AdminToken==undefined){
		// window.top.location.href="login.html";
	// }else{
		$.ajax({
		  "type": "POST",
		  "url": AllUrl +Url,
		  "async": true,
		  "headers": {
		    "content-type": "application/json",
		    "admintoken": localStorage.AdminToken,
		    },
		  "data": jsondata,
		  "success":function (jsonData ) {
		  	
		    callBack(jsonData , needkey)
		//      console.log(jsonData);
		//      console.log('当前'+Url+'接口的内容是：'+JSON.stringify(jsonData))
		  }
		})
	// }
  
}

function AjaxPostFn1(Url,jsondata,callBack  ,  needkey){
	if(localStorage.AdminToken==undefined){
		window.top.location.href="login.html";
	}else{
		$.ajax({
		  "type": "POST",
		  "url": Url,
		  "async": true,
		  "headers": {
		    "content-type": "application/json",
		    "admintoken": localStorage.AdminToken,
		    },
		  "data": jsondata,
		  "success":function (jsonData ) {
		  	
		    callBack(jsonData , needkey)
		//      console.log(jsonData);
		//      console.log('当前'+Url+'接口的内容是：'+JSON.stringify(jsonData))
		  }
		})
	}
  
}


function GetQueryString(name) {
	//	处理地址栏的参数
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r != null) return decodeURI(r[2]);
	return null;
}



(function($){
	//表单序列化转换成json格式
//$('.regist-from').serializeJson() //调用方式
    $.fn.serializeJson=function(){
        var serializeObj={};
        var array=this.serializeArray();
        var str=this.serialize();
        $(array).each(function(){
            if(serializeObj[this.name]){
                if($.isArray(serializeObj[this.name])){
                    serializeObj[this.name].push(this.value);
                }else{
                    serializeObj[this.name]=[serializeObj[this.name],this.value];
                }
            }else{
                serializeObj[this.name]=this.value;
            }
        });
        return serializeObj;
    };
    
    $.fn.serializeObject = function()    
	{    
	   var o = {};    
	   var a = this.serializeArray();    
	   $.each(a, function() {    
	       if (o[this.name]) {    
	           if (!o[this.name].push) {    
	               o[this.name] = [o[this.name]];    
	           }    
	           o[this.name].push(this.value || '');    
	       } else {    
	           o[this.name] = this.value || '';    
	       }    
	   });    
	   return o;    
	};  
})(jQuery);


function getMoth(str){  
    var oDate = new Date(str),  
    oMonth = oDate.getMonth()+1,  
    oDay = oDate.getDate(),  
    oTime = getzf(oMonth) +'-'+ getzf(oDay);//最后拼接时间  
    return oTime;  
};  
//console.log(getMoth(1465959000));//使用方法  

//new Date().getTime() long型时间获取
//获得年月日      得到日期oTime  
function getMyDate(str){  
    var oDate = new Date(str),  
    oYear = oDate.getFullYear(),  
    oMonth = oDate.getMonth()+1,  
    oDay = oDate.getDate(),  
    oHour = oDate.getHours(),  
    oMin = oDate.getMinutes(),  
    oSen = oDate.getSeconds(),  
    oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +' '+ getzf(oHour) +':'+ getzf(oMin) ;//最后拼接时间  
//  oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) +' '+ getzf(oHour) +':'+ getzf(oMin) +':'+getzf(oSen);//最后拼接时间  
    return oTime;  
};  



//补0操作  
function getzf(num){  
    if(parseInt(num) < 10){  
        num = '0'+num;  
    }  
    return num;  
}  

//获取当前时间，格式YYYY-MM-DD
function getNowFormatDate() {
    var date = new Date();
    var seperator1 = "-";
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
   
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    
    var currentdate = year + seperator1 + month + seperator1 + strDate;
    return currentdate;
}


function thisDay01(){
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var strDate = date.getDate();
   
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }
    
  
    return new Date(year,month-1,strDate,0,0,01).getTime();

}
function thisMouth01(){
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
  
   
    if (month >= 1 && month <= 9) {
        month = "0" + month;
    }

    
  
    return year+"-"+month+"-01"

}

//new Date().getTime() 获取long型的时间

//当前时间的获取
//获取时间的格式"2018-03-12 21:46:40.437"
function getnowtime() {  
	var nowtime = new Date();  
	var year = nowtime.getFullYear();  
	var month = padleft0(nowtime.getMonth() + 1);  
	var day = padleft0(nowtime.getDate());  
	var hour = padleft0(nowtime.getHours());  
	var minute = padleft0(nowtime.getMinutes());  
	var second = padleft0(nowtime.getSeconds());  
	var millisecond = nowtime.getMilliseconds(); millisecond = millisecond.toString().length == 1 ? "00" + millisecond : millisecond.toString().length == 2 ? "0" + millisecond : millisecond;  
	return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + "." + millisecond;  
}  

//获取时间的格式"2018-03-12 21:46:40.437"
function getnowhour() {  
	var nowtime = new Date();  
	var year = nowtime.getFullYear();  
	var month = padleft0(nowtime.getMonth() + 1);  
	var day = padleft0(nowtime.getDate());  
	var hour = padleft0(nowtime.getHours());  
	var minute = padleft0(nowtime.getMinutes());  
	
	var millisecond = nowtime.getMilliseconds(); millisecond = millisecond.toString().length == 1 ? "00" + millisecond : millisecond.toString().length == 2 ? "0" + millisecond : millisecond;  
	return year + "-" + month + "-" + day + " " + hour + ":" + minute ;  
}  

//补齐两位数  
function padleft0(obj) {  
    return obj.toString().replace(/^[0-9]{1}$/, "0" + obj);  
}  

//选择图片，马上预览
//onchange="xmTanUploadImg(this)"
function xmTanUploadImg(obj) {
	$(".upNewimg").val("确认上传");
    var file = obj.files[0];
    
//  console.log(obj);console.log(file);
//  console.log("file.size = " + file.size);  //file.size 单位为byte

    var reader = new FileReader();

    //读取文件过程方法
    reader.onloadstart = function (e) {
//      console.log("开始读取....");
    }
    reader.onprogress = function (e) {
//      console.log("正在读取中....");
    }
    reader.onabort = function (e) {
//      console.log("中断读取....");
    }
    reader.onerror = function (e) {
//      console.log("读取异常....");
    }
    reader.onload = function (e) {
//      console.log("成功读取....");

        var img = document.getElementById("xmTanImg");
        img.src = e.target.result;
        //或者 img.src = this.result;  //e.target == this
    }
	console.log(file);
    reader.readAsDataURL(file);
}


//点击图片放大
function TopimgFn(){
	$(".classifyimg").click(function(){
	  	var that = this;
	  	layer.open({
		  	type: 1, 
		  	content: '<img src="'+$(this).attr("src")+'" class="openimg" / >', //这里content是一个普通的String
//		  	area: ['500px'],
		  	title: false,
		  
		  	shadeClose:true,
		  	resizing: function(layero){
			  	console.log(layero);
			},
			cancel: function(){
				layer.closeAll();
//				    layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', {time: 5000, icon:6});
			}
		});
	})
}

//ajax数据传给表单
function putJsonToForm(jsonValue,formId){
    var obj = $("#"+formId);
    $.each(jsonValue, function(name, ival) {
        var $oinput = obj.find("input[name='" + name + "']");
        if ($oinput.attr("type") == "radio"
                || $oinput.attr("type") == "checkbox") {
            $oinput.each(function() {
                if (Object.prototype.toString.apply(ival) == '[object Array]') {//是复选框，并且是数组         
                    for (var i = 0; i < ival.length; i++) {
                        if ($(this).val() == ival[i])
                        $(this).attr("checked", true);
                    }
                } else if(!ival){
                		$(this).attr("checked", false);
                }else {
                    if ($(this).val() == ival)
                        $(this).attr("checked", true);
                }
            });
        } else if ($oinput.attr("type") == "textarea") {//多行文本框            
            obj.find("[name=" + name + "]").html(ival);
        } else {
            obj.find("[name=" + name + "]").val(ival);
        }
    });	
}


function inputisNull(obj,callback){
	//判断当前的必填项是否为空
	var list = $(obj);
	for (var i = 0; i < list.length; i++) {
		// 判断是否为文本框
		if (list[i].type == "text") {
		// 判断文本框是否为空
			if (list[i].value == "") {
				layer.msg("请将信息填写完成");
				return false;
				
				
			}
			
		}
		
	}
	callback();
	
}



function tableToJson(){
//	 var tabLen = document.getElementById("tableID");
//      var jsonT = "[";
//      for (var i = 1; i < tabLen.rows.length; i++) {
//              jsonT += '{"ID":' + tabLen.rows[i].cells[0].innerHTML + ',"Name":"' + tabLen.rows[i].cells[1].innerHTML + '","Age":' + tabLen.rows[i].cells[2].innerHTML + ',"Gender":"' + tabLen.rows[i].cells[3].innerHTML + '"},'
//      }
//      jsonT= jsonT.substr(0, jsonT.length - 1);
//      jsonT += "]";
//      console.log(jsonT);
}


function postJsonWithConsoleHeaderToken(postUrl, paraJson, callback) {
	//okodmjs
    $.ajax({
        type: "post",
        url: postUrl,
        data: JSON.stringify(paraJson),
        headers: { "accessToken": store.get(system_config.console_access_token), "ostype": 1 },
        contentType: "application/json; charset=utf-8",
        dataType: 'json', //返回数据类型   
        success: function(jsonData, textStatus) {
        	if (jsonData.resultCode == "401") {
        		window.location = "../admintest/login.html"
        	}else{
        		callback(jsonData);
        	}
            
        },
        error: function() {
            //			alert("异常"+postUrl);
        }
    });
}


function Arabia_to_Chinese(Num) {
	//将价格转换成中文大写
	console.log(Num)
    for (i = Num.length - 1; i >= 0; i--) {
        Num = Num.replace(",", "");
        Num = Num.replace(" ", "");
    }
    //1
    Num = Num.replace("￥", "")
    if (isNaN(Num)) {
        return;
    }
    part = String(Num).split(".");
    newchar = "";
    for (i = part[0].length - 1; i >= 0; i--) {
        if (part[0].length > 10) {
            return "";
        }
        tmpnewchar = ""
        perchar = part[0].charAt(i);
        switch (perchar) {
            case "0": tmpnewchar = "零" + tmpnewchar; break;
            case "1": tmpnewchar = "壹" + tmpnewchar; break;
            case "2": tmpnewchar = "贰" + tmpnewchar; break;
            case "3": tmpnewchar = "叁" + tmpnewchar; break;
            case "4": tmpnewchar = "肆" + tmpnewchar; break;
            case "5": tmpnewchar = "伍" + tmpnewchar; break;
            case "6": tmpnewchar = "陆" + tmpnewchar; break;
            case "7": tmpnewchar = "柒" + tmpnewchar; break;
            case "8": tmpnewchar = "捌" + tmpnewchar; break;
            case "9": tmpnewchar = "玖" + tmpnewchar; break;
        }
        switch (part[0].length - i - 1) {
            case 0: tmpnewchar = tmpnewchar + "元"; break;
            case 1: if (perchar != 0) tmpnewchar = tmpnewchar + "拾"; break;
            case 2: if (perchar != 0) tmpnewchar = tmpnewchar + "佰"; break;
            case 3: if (perchar != 0) tmpnewchar = tmpnewchar + "仟"; break;
            case 4: tmpnewchar = tmpnewchar + "万"; break;
            case 5: if (perchar != 0) tmpnewchar = tmpnewchar + "拾"; break;
            case 6: if (perchar != 0) tmpnewchar = tmpnewchar + "佰"; break;
            case 7: if (perchar != 0) tmpnewchar = tmpnewchar + "仟"; break;
            case 8: tmpnewchar = tmpnewchar + "亿"; break;
            case 9: tmpnewchar = tmpnewchar + "拾"; break;
        }
        newchar = tmpnewchar + newchar;
    }
    if (Num.indexOf(".") != -1) {
        if (part[1].length > 2) {
            alert("小数点之后只能保留两位,系统将自动截段");
            part[1] = part[1].substr(0, 2)
        }
        for (i = 0; i < part[1].length; i++) {//for2
            tmpnewchar = ""
            perchar = part[1].charAt(i)
            switch (perchar) {
                case "0": tmpnewchar = "零" + tmpnewchar; break;
                case "1": tmpnewchar = "壹" + tmpnewchar; break;
                case "2": tmpnewchar = "贰" + tmpnewchar; break;
                case "3": tmpnewchar = "叁" + tmpnewchar; break;
                case "4": tmpnewchar = "肆" + tmpnewchar; break;
                case "5": tmpnewchar = "伍" + tmpnewchar; break;
                case "6": tmpnewchar = "陆" + tmpnewchar; break;
                case "7": tmpnewchar = "柒" + tmpnewchar; break;
                case "8": tmpnewchar = "捌" + tmpnewchar; break;
                case "9": tmpnewchar = "玖" + tmpnewchar; break;
            }
            if (i == 0) tmpnewchar = tmpnewchar + "角";
            if (i == 1) tmpnewchar = tmpnewchar + "分";
            newchar = newchar + tmpnewchar;
        }
    }
    while (newchar.search("零零") != -1)
        newchar = newchar.replace("零零", "零");
    newchar = newchar.replace("亿零万", "亿");
    newchar = newchar.replace("零亿", "亿");
    newchar = newchar.replace("亿万", "亿");
    newchar = newchar.replace("零万", "万");
    newchar = newchar.replace("零元", "元");
    newchar = newchar.replace("零角", "");
    newchar = newchar.replace("零分", "");
 
    if (newchar.charAt(newchar.length - 1) == "元" || newchar.charAt(newchar.length - 1) == "角")
        newchar = newchar + "整"
    return newchar;
}

		